# -*- coding: utf-8 -*-
# @Time : 2022/6/21 下午2:05
# @Author : wyf
# @FileName: login.py
# @Email: yunfei.wang@innvote.com

"""

天翼云登录

url: https://m.ctyun.cn/wap/main/auth/login?redirect=%2Faccount%2Frealname

"""
from pprint import pprint
from traceback import print_exc

import execjs
import requests



def js_from_file(file_name):
    """
    读取js文件
    :return:
    """
    with open(file_name, 'r', encoding='UTF-8') as file:
        result = file.read()

    return result

# 编译加载js字符串
context = execjs.compile(js_from_file('./login.js'))

username = "lxb_wyf@163.com"  # 帐号
password = "17639569679@163.com"       # 密码
res = context.call("data", username, password)   # 调用js方法
pprint(res)

url = "https://m.ctyun.cn/account/login"

headers = {
    "Accept": "application/json, text/plain, */*",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Connection": "keep-alive",
    "Host": "m.ctyun.cn",
    "Referer": "https://m.ctyun.cn/wap/main/auth/login?redirect=%2Faccount%2Frealname",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-origin",
    "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
}

req = requests.get(url, params=res, headers=headers)
print(req)
req.encoding = "utf-8"
print(req.text)


"""
{'comParam_curTime': 1655885395599,
 'comParam_seqCode': '3A4157811264349C4AC89A2C607478BA',
 'comParam_signature': 'b342928f0abd2593897fb26ec825a1e6',
 'isCheck': 'true',
 'locale': 'zh-cn',
 'mainVersion': '300021100',
 'password': '3RKBy+StO3r9sKxL8SFr0RUydu1+vzvB',
 'referrer': 'wap',
 'userName': 'lxb_wyf@163.com'}
<Response [200]>
{"resultCode":"0","resultMsg":"success","data":{"token":"9b9a2298-75d8-4f83-94c8-d07a683e6ecf","userId":"d20f5729963644c6a74f2d438f9c8321","accountId":"b4a61a5539c64f2cb59ec8ee0a3ef1a5","loginEmail":"lxb***@163.com","requestDate":1655885406806,"accountType":null,"productNbr":null,"proUserInnerId":null,"isHavePrivilege":null,"expires":31536000,"accountMd":"3RKBy+StO3r9sKxL8SFr0RUydu1+vzvB","refer":"wap","innerUserId":"21386327","rootUserId":"d20f5729963644c6a74f2d438f9c8321","isRoot":1,"userInfo":{"accountType":"1","userId":"d20f5729963644c6a74f2d438f9c8321","accountId":"b4a61a5539c64f2cb59ec8ee0a3ef1a5","auditStatus":"0","auditStatusVo":"未实名认证","auditMsg":"","telephone":null,"address":null,"postNo":null,"mobilephone":"176****9679","email":"lxb***@163.com","name":"l*************m","subType":null,"channel":"1","productNbr":null,"isPostpaid":"0","province":"0","city":"0","county":"0","cardType":null,"isAgent":null,"invalidStatus":null,"encryptStr":null,"aesKey":null,"sex":null,"cardNo":null,"idCardPathBean":null}},"extendObj":null,"success":true}

"""

